//
//  HomeSortCell.m
//  Cat
//
//  Created by lushitong on 2018/12/18.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#import "HomeSortCell.h"
#import "HomeSortView.h"

@interface HomeSortCell()

@property (nonatomic, strong) NSMutableArray *viewArray;

@end

@implementation HomeSortCell

- (void)setDelegate:(id<HomeSortDelegate>)delegate {
	_delegate = delegate;
}

- (void)setSortArray:(NSArray *)sortArray {
	_sortArray = sortArray;
	for (NSInteger i = 0 ; i < self.viewArray.count; i++) {
		HomeSortView *view = (HomeSortView *)[self.viewArray safeObjectAtIndex:i];
		view.model = (CategortModel *)[sortArray safeObjectAtIndex:i];
	}
}

- (instancetype)initWithFrame:(CGRect)frame {
	self = [super initWithFrame:frame];
	if (self) {
		self.contentView.backgroundColor = COLOR_WITH_HEX(0xFAFAFA);
		[self loadAllSubview];
	}
	return self;
}

- (void)loadAllSubview {
	for (int i = 0; i < 5; i++) {
		HomeSortView *view = [[HomeSortView alloc] init];
		[self.contentView addSubview:view];
		[self.viewArray addObject:view];
	}
	
	CGFloat left = 17.0;
	for (NSInteger i = 0 ; i < self.viewArray.count; i++) {
		HomeSortView *view  = [self.viewArray safeObjectAtIndex:i];
		[view mas_makeConstraints:^(MASConstraintMaker *make) {
			make.size.equalTo(CGSizeMake([self getIconSize:5].width, self.height));
			make.top.equalTo(self.contentView.top).offset(kQKFitModuleDecimal(20.0));
			make.left.equalTo(self.contentView.mas_left).offset(@(left));
		}];
		left = left + [self getIconSize:5].width + kQKFitModuleDecimal(30.0);
	}
}

- (CGSize)getIconSize:(NSUInteger)count {
	CGFloat width = (ScreenWidth - kQKFitModuleDecimal(17.0) * 2 - 4 * kQKFitModuleDecimal(30.0)) / 5;
	return CGSizeMake(width, width);
}

- (NSMutableArray *)viewArray {
	if (!_viewArray) {
		_viewArray = [[NSMutableArray alloc] init];
	}
	return _viewArray;
}

@end

